/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package libase.web.jsf.bean;

import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Named;
import libase.entity.Author;

/**
 *
 * @author aspr0
 */
@Named
@Stateless
//todo consider separating crud tasks within entitys using RequestScoped there
public class AuthorBean extends AbstractBean
{
    private Author a = new Author();

    public Author getA()
    {
        if (fetchId())
        {
            return a = em.find(Author.class, id);
        }

        return a;
    }

    public void setA(Author a)
    {
        this.a = a;
    }

    public List<Author> getAuthors()
    {
        return em.createNamedQuery("Author.findAll").getResultList();
    }

    public void create()
    {
        em.persist(a);
        a = new Author();
    }

    public void edit()
    {
        em.merge(a);
        a = new Author();
    }

    public void remove()
    {
        getA();
        em.remove(a);
        a = new Author();
    }
}
